package ms.jacrim.tropos;

import org.w3c.dom.Element;

public class Composition extends Relationship {

//	public static final String AND = "AND";
//	public static final String OR = "OR";

	public enum Type {
		AND, OR
	};

	private static final String COMPOSITION_TEMPLATE = "<object xmi:type=\"%s\" xmi:id=\"%s\""
			+ " source=\"%s\" target=\"%s\" compositionType=\"%s\" />\r\n";

	private Type compositionType;

	public Composition(Diagram diagram, TroposObject source, TroposObject target) {
		super(diagram, source, target);
		setType(TroposObject.COMPOSITION);
		setName("Composition");
		setCompositionType(Type.AND);
	}

	public Composition(Diagram diagram, Element element) {
		super(diagram, element);
	}

	void populate(Element element) {
		super.populate(element);

		this.compositionType = Type.valueOf(element.getAttribute("compositionType"));
	}

	public Type getCompositionType() {
		return compositionType;
	}

	public void setCompositionType(Type compositionType) {
		this.compositionType = compositionType;
	}

	void toString(StringBuilder result, int part, int indent) {
		super.toString(result, part, indent);
		if (part == 0) {
			writeIndent(result, indent);
			result.append(String.format(COMPOSITION_TEMPLATE, this.getType(), this.getId(), this.getSourceId(), this.getTargetId(),
				this.compositionType));
		}
	}

	@Override
	protected int NotationEdgeType() {
		// TODO Auto-generated method stub
		return 3003;
	}
}
